<?php 
/**
 *手机信息静态设置
 */
class PhoneInfo{
	/**
	 * 注册帐号
	 * @param $phone
	 * @param $imsi
	 * @param $version
	 */
	public static function getAddUser($phone , $imsi , $version){
		$Db = loadDB();
		$time = date("Y-m-d H:i:s");
		//把数据写入数组
		$insert_date = array(
			'phone' => $phone,
			'imsi' => $imsi,
			'version' => $version,
			'dtime' => $time,
		);
		$success = $Db->doInsert('user' , $insert_date);
		return $success ? 0 : 100;
	}
	/**
	 * 写入信息
	 * @param $phone
	 * @param $imsi
	 * @param $version
	 */
	public static function getAddMsg($sender , $receiver , $ctype , $content){
		$Db = loadDB();
		$time = date("Y-m-d H:i:s");
		//把数据写入数组
		$insert_date = array(
			'sender' => $sender,
			'receiver' => $receiver,
			'ctype' => $ctype,
			'content' => $content,
			'dtime' => $time,
			'readed' => 0,
		);
		$success = $Db->doInsert('msg' , $insert_date);
		return $success ? 0 : 101;
	}
	/**
	 * 查询帐号信息
	 * @param unknown_type $phone
	 */
	public static function getOneUser($phone){
		$Db = loadDB();
		$result = $Db->getOne("SELECT * FROM `user` WHERE `phone` = {$phone}");
		
		return $result;
	}
	/**
	 * 查询用户未读信息
	 * @param unknown_type $receiver
	 */
	public static function getAllMsg($receiver){
		
		$Db = loadDB();
		$result = $Db->getAll("SELECT `id`,`ctype` , `sender` , `dtime` , `content` FROM `msg` WHERE `receiver` = {$receiver} and `readed` = 0 ORDER BY dtime DESC");
	
		return $result;
	}
	/**
	 * 修改状态
	 * @param <int> $id
	 */
	public static function getAlterReaded($id){
		$Db=loadDB();
		
		$success =$Db->query("UPDATE msg SET readed=1 WHERE id IN ({$id})");
		
		return $success ? 0 : 102;
	}
	/**
	 * 查询多帐号信息
	 * @param unknown_type $phone
	 */
	public static function getAllUser($phone){
		$Db = loadDB();
		$result = $Db->getAll("SELECT * FROM `user` WHERE `phone` IN {$phone}");
		
		return $result;
	}
}
# end of script